package com.funny.test.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.ImportAware;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;

import java.util.Map;

/**
 * @author fanxiao  2021/9/27
 * @since 1.0.0
 */
@Slf4j
public class ImportAwareConfiguration implements ImportAware {

	private boolean enable;

	private String value;


	@Override
	public void setImportMetadata(AnnotationMetadata importMetadata) {
		Map<String, Object> map = importMetadata.getAnnotationAttributes(EnableImportAware.class.getName());
		AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(map);
		this.enable = annotationAttributes.getBoolean("enable");
		this.value = annotationAttributes.getString("value");
		if (!enable){
			throw new IllegalArgumentException("IllegalArgumentException");
		}
	}
}
